昨天部署完 kubernetes master 節點後,再來就可以部署 worker 節點。
利用部署 master 節點時,指令 kubeadm init...
提供的訊息,即可進行 worker 節點的部署。
KUBERNETES_VERSION='=1.15.0-00'
for NODE in worker1 worker2
do
ssh ${NODE} "
sudo apt update -y;
sudo apt install -y apt-transport-https curl gpg;
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - ;
echo 'deb https://apt.kubernetes.io/ kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list ;
sudo apt update -y ;
sudo apt install -y kubelet${KUBERNETES_VERSION} kubeadm${KUBERNETES_VERSION} kubectl${KUBERNETES_VERSION} ;
sudo apt-mark hold kubelet kubeadm kubectl ;
sudo swapoff -a ;
sudo sed -i -e 's/^\\([^#].*swap.*\\)$/#\\1/g' /etc/fstab ;
"
done
TOKEN=$(cat init | grep 'kubeadm join' | rev| cut -d' ' -f2 | rev)
HASH=$(cat init | grep 'discovery-token-ca-cert-hash' | rev | cut -d: -f1 | rev)
for NODE in worker1 worker2
do
ssh ${NODE} "sudo kubeadm join ${MASTERIP}:6443 --token ${TOKEN} --discovery-token-ca-cert-hash sha256:${HASH}"
done
如此即完成 kubernetes 的 master 及 worker 節點部署,有了最基本的 kubernetes 群集。
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master1 Ready master 9m54s v1.15.0
worker1 NotReady <none> 69s v1.15.0
worker2 NotReady <none> 98s v1.15.0